--- 模块功能：lcddemo
-- @module lcd
-- @author Dozingfiretruck
-- @release 2021.01.25

-- LuaTools需要PROJECT和VERSION这两个信息
PROJECT = "lcddemo"
VERSION = "1.0.0"

log.info("main", PROJECT, VERSION)

-- sys库是标配
_G.sys = require("sys")


lcd.init("jd9261t_inited",{port = lcd.HWID_0,pin_dc = 0xff, pin_pwr = 24, pin_rst = 36,direction = 0,w = 480,h = 480,xoffset = 0,yoffset = 0,interface_mode=lcd.QSPI_MODE,bus_speed=60000000,flush_rate=658,vbp=19,vfp=108,vs=2})


sys.taskInit(function()
    lcd.setupBuff(nil, true) -- 使用sys内存, 只需要选一种
    lcd.autoFlush(false)

    while 1 do 
        lcd.clear()
        log.info("wiki", "https://wiki.luatos.com/api/lcd.html")
        -- API 文档 https://wiki.luatos.com/api/lcd.html
        if lcd.showImage then
            -- 注意, jpg需要是常规格式, 不能是渐进式JPG
            -- 如果无法解码, 可以用画图工具另存为,新文件就能解码了
            lcd.showImage(40,0,"/luadb/logo.jpg")
            sys.wait(100)
        end
        log.info("lcd.drawLine", lcd.drawLine(20,20,150,20,0x001F))
        log.info("lcd.drawRectangle", lcd.drawRectangle(20,40,120,70,0xF800))
        log.info("lcd.drawCircle", lcd.drawCircle(50,50,20,0x0CE0))

        lcd.flush()

        sys.wait(5000)
    end
end)
if tp then
    local function tp_callBack(tp_device,tp_data)
        sys.publish("TP",tp_device,tp_data)
		log.info("TP",tp_data[1].x,tp_data[1].y,tp_data[1].event)
    end
    
    tp_device = tp.init("jd9261t_inited",{port=1,pin_rst = 255,pin_int = 22,w = 480,h = 480,int_type=gpio.FALLING},tp_callBack)

    if tp_device then
        print(tp_device)
        sys.taskInit(function()
            while 1 do 
                local result, tp_device, tp_data = sys.waitUntil("TP")
                if result then
                    lcd.drawPoint(tp_data[1].x, tp_data[1].y, 0xF800)
                    lcd.flush()
                end
            end
        end)
    end
end
sys.run()

